﻿using Sunny.UI;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace CoreShop.App
{
    public partial class UIDishItemXp : UIUserControl
    {
        public UIDishItemXp()
        {
            InitializeComponent();
            Info = new DishItemInfo();
            Text = Info.Name;
        }


        private Image image;
        public Image Image
        {
            get { return image; }
            set
            {
                image = value;
                Width = value == null ? 133 : 202;
                Invalidate();
            }
        }

        public DishItemInfo Info { get; }
        public UIDishItemXp(DishItemInfo info)
        {
            InitializeComponent();
            if (info == null)
            {
                throw new NullReferenceException("info");
            }

            Info = info;
            Text = info.Name;
        }

        public string TextName
        {
            get => Text;
            set
            {
                Text = value;
                Invalidate();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (Info == null) return;

            StringFormat sf = new StringFormat();
            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment = StringAlignment.Center;

            if (image != null)
            {
                e.Graphics.DrawImage(Image, new Rectangle(46, 0, 105, 105), new Rectangle(0, 0, Image.Width, image.Height), GraphicsUnit.Pixel);
            }
            using (Font font = new Font("微软雅黑", 11.5f))
            {
                e.Graphics.DrawString(Info.Number, font, Brushes.Gray, new Rectangle(0, 104, 204, 24), sf);
            }

            using (Font font = new Font("微软雅黑", 14f))
            {
                //sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString(Info.Name, font, Brushes.Black, new Rectangle(0, 118, 204, 56), sf);
            }

            using (Font font = new Font("微软雅黑", 12f))
            {                
                e.Graphics.DrawString(Info.Price + "/"+ Info.UnitName, font, Color.Chocolate, 0, 170);
            }
        }

    }
}